<style>
.oneline{margin: 4px 0;}
	.txtInput.number{width:50px !important;}
</style>
<table class="easyui-datagrid" id="scholarList" 
  	data-options="url:'uni/scholars',fit:true,fitColumns:true,rownumbers:true,pagination:true,pageSize:20,pageList:[10,20,25,50,100],toolbar:scholarToolbar">
  	<thead>
        <tr>
        	<th data-options="field:'ck',checkbox:true"></th>
            <th data-options="field:'name',halign:'center',width:120">奖助学金名称</th>
            <th data-options="field:'level',align:'center',width:60">档数</th>
            <th data-options="field:'startMonth',align:'center',width:60">起始月份</th>
            <th data-options="field:'endMonth',align:'center',width:60">结束月份</th>
            <th data-options="field:'frequency',align:'center',width:60">频率</th>
            <th data-options="field:'lastGrant',align:'center',width:60">上次发放日期</th>
        </tr>
    </thead>
</table>

<div id="win_scholar" class="easyui-window" title="编辑/添加奖助学金" style="width:580px;height:630px;"
        data-options="iconCls:'icon-save',modal:true,closed:true,minimizable:false,collapsible:false,maximizable:false">
  <form id="f_scholarAct" action="uni/scholarAct" method="post">
  	  <input type="hidden" id="action" name="action" value="">
  	  <input type="hidden" id="scholarId" name="scholarId" value="">
      <table class="form_table" style="border:0px;">
      	  <tr>
      	  	<td colspan="2"><span style="color:red;">1.如果需要限定奖助学金每几个月只能发放一次，则需要填写奖学金的周期、频率信息。<br/>
      	  	2.周期表示奖助学金的生命周期（从开始时间到结束时间），频率表示每几个月发放一次。<br/>
      	  	3.如果不需要该限制，只需要将奖助学金的开始时间与结束时间置空即可。</span></td>
      	  </tr>
          <tr>
              <td>奖助学金：</td>
              <td style="line-height:normal;">
              <div class="oneline">
              	名称：<input name="name" type="text" class="txtInput" ></input> 档数：<select id="level" class="select" name="level">
              		<option value="1">1</option>
              		<option value="2">2</option>
              		<option value="3" selected="selected">3</option>
              		<option value="4">4</option>
              		<option value="5">5</option>
              		<option value="6">6</option>
              		<option value="7">7</option>
              		<option value="8">8</option>
              		<option value="9">9</option>
              	</select>
              </div>
              <div class="oneline">
              	周期：<input type="text" id='startMonth' name="startMonth" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'endMonth\');}',dateFmt:'yyyy年MM月'})" class="Wdate" style="margin-right: 5px;padding: 0 3px 0 3px;background-color: #FAFAFA;border: 1px solid #D7D7D7;vertical-align: middle;font-size: 12px;font-family: '微软雅黑';height:22px;line-height:22px;"/>
              	- <input type="text" id="endMonth" name="endMonth" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'startMonth\');}',dateFmt:'yyyy年MM月'})" class="Wdate" style="margin-right: 5px;padding: 0 3px 0 3px;background-color: #FAFAFA;border: 1px solid #D7D7D7;vertical-align: middle;font-size: 12px;font-family: '微软雅黑';height:22px;line-height:22px;"/>
              </div>
              <div class="oneline">频率：每 <input id="frequency" name="frequency" class="easyui-numberspinner" style="width:50px;" data-options="min:1,value:1,max:24,onChange:countTimes"></input> 月,
              	次数：<span id="times"></span>
              </div>
				  <div class="oneline">
					  对象：<input name="person" type="checkbox" checked class="txtInput" value="1">一年级
					  <input name="person" type="checkbox" checked class="txtInput" value="2">二年级
					  <input name="person" type="checkbox" checked class="txtInput" value="3">三年级
					  <input name="person" type="checkbox" checked class="txtInput" value="4">四年级
					  <input name="person" type="checkbox" checked class="txtInput" value="5">五年级
				  </div>
				  <div class="oneline">
					  条件1：<input name="person" type="text" class="txtInput" value="">
				  </div>
				  <div class="oneline">
					  条件2：<input name="person" type="text" class="txtInput" value=""><img src="statics/css/themes/icons/edit_add.png">
				  </div>
				  <div class="oneline">
					  分配方式：<input name="me1" type="radio" class="txtInput" checked value="1" onchange="switchFpfs();">按系分配 <input name="me1" type="radio" class="txtInput" value="2" onchange="switchFpfs();">按班分配
				  </div>

				  <div class="oneline eee1">
					  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;烹饪系<input name="me3" type="text" class="txtInput number" value=""> 旅游系<input name="me3" type="text" class="txtInput number" value=""> 信息系<input name="me3" type="text" class="txtInput number" value="">
				  </div>
				  <div class="oneline eee1">
					  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;商务系<input name="me3" type="text" class="txtInput number" value=""> 工艺系<input name="me3" type="text" class="txtInput number" value=""> 经贸系<input name="me3" type="text" class="txtInput number" value="">
				  </div>
				  <div class="oneline eee2" style="display: none;">
					  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;每班<input name="me4" type="text" class="txtInput number" value="">
				  </div>
				  <div class="oneline">
					  名额限制：<input name="me2" type="radio" class="txtInput" checked value="1">按人数 <input name="me2" type="radio" class="txtInput" value="2">按比例
				  </div>


				  <div class="oneline">
					  金额：<input name="person" type="text" class="txtInput" value="">
					  评定时间：<input name="person" type="text" onfocus="WdatePicker({dateFmt:'yyyy年MM月'})" class="txtInput" value="">
				  </div>
				  <div class="oneline">
					  申报材料：<input name="person" type="file" class="txtInput" value="">
				  </div>
              </td>
          </tr>
          <tr id="win_scholar_tr_1">
              <td>档次1：</td>
              <td>
              	名称：<input name="name1" type="text" class="txtInput" value="一等奖">
              	金额：<input name="money1" type="text" class="txtInput"></input></td>
          </tr>
          <tr id="win_scholar_tr_2">
              <td>档次2：</td>
              <td>
              	名称：<input name="name2" type="text" class="txtInput" value="二等奖">
              	金额：<input name="money2" type="text" class="txtInput" ></input></td>
          </tr>
          <tr id="win_scholar_tr_3">
              <td>档次3：</td>
              <td>
              	名称：<input name="name3" type="text" class="txtInput" value="三等奖">
              	金额：<input name="money3" type="text" class="txtInput" ></input></td>
          </tr>
          <tr id="win_scholar_tr_4">
              <td>档次4：</td>
              <td>
              	名称：<input name="name4" type="text" class="txtInput" >
              	金额：<input name="money4" type="text" class="txtInput" ></input></td>
          </tr>
          <tr id="win_scholar_tr_5">
              <td>档次5：</td>
              <td>
              	名称：<input name="name5" type="text" class="txtInput" >
              	金额：<input name="money5" type="text" class="txtInput" ></input></td>
          </tr>
          <tr id="win_scholar_tr_6">
              <td>档次6：</td>
              <td>
              	名称：<input name="name6" type="text" class="txtInput" >
              	金额：<input name="money6" type="text" class="txtInput" ></input></td>
          </tr>
          <tr id="win_scholar_tr_7">
              <td>档次7：</td>
              <td>
              	名称：<input name="name7" type="text" class="txtInput" >
              	金额：<input name="money7" type="text" class="txtInput" ></input></td>
          </tr>
          <tr id="win_scholar_tr_8">
              <td>档次8：</td>
              <td>
              	名称：<input name="name8" type="text" class="txtInput" >
              	金额：<input name="money8" type="text" class="txtInput" ></input></td>
          </tr>
          <tr id="win_scholar_tr_9">
              <td>档次9：</td>
              <td>
              	名称：<input name="name9" type="text" class="txtInput" >
              	金额：<input name="money9" type="text" class="txtInput" ></input></td>
          </tr>
          <tr>
              <td></td>
              <td><input type="submit" value="确定" class="btnSubmit"></input>&nbsp;
              <input type="button" onclick="$('#win_scholar').window('close');" value="取消" class="btnSubmit" ></input></td>
          </tr>
      </table>
  </form>
</div>
<script type="text/javascript" src="statics/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="statics/js/xdate.js"></script>
<script>
$(function(){
	
	$('#level').change(function() {
		for(var i = 0; i <= 9 ; i++) {
			if(i <= $('#level').val()) {
				$('#win_scholar_tr_' + i).show();
			} else {
				$('#win_scholar_tr_' + i).hide().find('input').val('');
			}
		}
	}).change();

	$('#f_scholarAct').form({
		 success : function(result){
            if($.parseJSON(result).errorInfo == 'none') {
            	$.messager.alert('提示','奖助学金设置成功！');
            	$('#win_scholar').window('close');
            	$('#scholarList').datagrid('reload');
				return ;
            } 
            $.messager.alert('提示',$.parseJSON(result).errorInfo);
        }
	});
});
var scholarToolbar = [{
    text:'添加',
    iconCls:'icon-add',
    handler:addScholar
},{
    text:'删除',
    iconCls:'icon-cut',
    handler:delScholar
},'-',{
    text:'修改',
    iconCls:'icon-save',
    handler:editScholar
}];

function countTimes(newValue,oldValue) {
	var months = ($('#endMonth').val().substr(0,4) - $('#startMonth').val().substr(0,4)) * 12
		+ ($('#endMonth').val().substr(5,2) - $('#startMonth').val().substr(5,2)) + 1;
	var counts = Math.floor(months / newValue);
	$('#times').html(counts > 1 ? counts : 1);
}

function addScholar() {
	//默认日期
	var now = new XDate();

	$('#startMonth').val(now.toString('yyyy年MM月'));
	$('#endMonth').val(now.addYears(1).toString('yyyy年MM月'));
	$('#frequency').numberbox('setValue', 2).numberbox('setValue', 1);//trigger countTimes
	
	$('#action').val('add');
	//清理现场
	$('#scholarId').val('');
	$('input[name=name]').val('');
	$('#level').val(3).change();
	$('input[name=name1]').val('一等奖');
	$('input[name=money1]').val('');
	$('input[name=name2]').val('二等奖');
	$('input[name=money2]').val('');
	$('input[name=name3]').val('三等奖');
	$('input[name=money3]').val('');
	
	$('#win_scholar').window('open');
}

function delScholar() {
	var scholarList = $('#scholarList').datagrid('getChecked');
	if(scholarList.length < 1) {
		$.messager.alert('提示','请至少选择一条数据！');
		return;
	}
	
	$.messager.confirm("提示","确认删除所选记录么？",function(r) {
		if(r) {
			$.each(scholarList,function(id,row) {
				$.ajax({
					url:'uni/scholarAct',
					data:'action=del&scholarId=' + row.id
				});
			});

			$.messager.alert('提示','删除成功！');
			$('#scholarList').datagrid('reload');
		}
	});
}

function editScholar() {
	var scholarList = $('#scholarList').datagrid('getChecked');
	if(scholarList.length != 1) {
		$.messager.alert('提示','请务必选择一条记录进行编辑！(只能选择一条)');
		return;
	}
	$('#action').val('edit');
	$('#scholarId').val(scholarList[0].id);
	$('input[name=name]').val(scholarList[0].name);
	$('#startMonth').val(scholarList[0].startMonth);
	$('#endMonth').val(scholarList[0].endMonth);
	$('#frequency').numberbox('setValue', scholarList[0].frequency);
	$('#level').val(scholarList[0].level).change();
	// LEVELS
	$.ajax({
		url:'uni/scholarLevels/'+ scholarList[0].id,
		success:function(result) {
			$.each(result,function(id,row){
				$('input[name=name' + row.level + ']').val(row.name);
				$('input[name=money' + row.level + ']').val(row.money);
			});
		}
	});
	$('#win_scholar').window('open');
}

	function switchFpfs() {
		if($('[name=me1]:checked').val() == 1) {
			$('.eee1').show();
			$('.eee2').hide();
		} else {
			$('.eee2').show();
			$('.eee1').hide();
		}
	}
</script>